using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Betarium.PotonEditor
{
	public class ToolInfoErase : ToolInfo
	{
		Point m_CurrentPos;
		int m_nWidth = 2;
		public ToolInfoErase(EditViewForm form)
			: base(form)
		{
		}

		public override void OnMouseDown(object sender, MouseEventArgs e)
		{
			m_Form.SelectState.OnMouseDown(sender, e);
			Point cursorPos = m_Form.SelectState.MouseCurrentPos;

			if (e.Button == MouseButtons.Left)
			{
                this.m_Form.AddUndo();
                Graphics graph = Graphics.FromImage(m_Form.Image);
				OnDraw(graph);
				graph.Dispose();
				SetModified();
			}
		}

		public override void OnDraw(Graphics graph)
		{
			Point cursorPos = m_Form.SelectState.MouseCurrentPos;
			cursorPos.X = cursorPos.X - 1;
			cursorPos.Y = cursorPos.Y - 1;
			graph.FillRectangle(new SolidBrush(Color.White), new Rectangle(cursorPos, new Size(m_nWidth, m_nWidth)));
		}
		public override void OnMouseMove(object sender, MouseEventArgs e)
		{
			m_Form.SelectState.OnMouseMove(sender, e);
			Point mouseMoveBefore = m_Form.SelectState.MouseBeforePos;
			Point cursorPos = m_Form.TransformClientToImage(e.Location);
			m_CurrentPos = cursorPos;

			if (m_Form.SelectState.MouseLeftDown)
			{
                this.m_Form.AddUndo();
                Graphics graph = Graphics.FromImage(m_Form.Image);
				Pen pen = new Pen(Color.White, m_nWidth);
				pen.LineJoin = LineJoin.MiterClipped;
				graph.DrawLine(pen, mouseMoveBefore, cursorPos);
				OnDraw(graph);
				graph.Dispose();
				SetModified();
			}
		}
		public override void OnPaint(object sender, PaintEventArgs e)
		{
			Rectangle rect = new Rectangle(m_CurrentPos, new Size(m_nWidth, m_nWidth));
			OnDraw(e.Graphics);
			m_Form.Cursor = Cursors.Cross;
		}
	}
}
